home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / SKTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  4.4 KB  |  152 lines

  1. // This program calls most of the functions in TxUnit and Keybrd
  2.  
  3. #include <dos.h>
  4. #include "txunit.h"
  5. #include "keybrd.h"
  6.  
  7. main()
  8. {
  9.   int K, X, Y;
  10.  
  11.   TxBuff Scrn(VideoPtr());
  12.   Scrn.SetSize(80, 25);  // REMEMBER TO ALWAYS CALL SETSIZE
  13.  
  14.   // Put a white fill pattern on the screen 
  15.  
  16.   Scrn.Fill(0, 0, 80, 25, 176, 0x0f);
  17.  
  18.   // Alias another txbuff region to start at (30,7)   
  19.   // Note that the size must still reflect full scrn! 
  20.  
  21.   TxBuff Win(Scrn.Txram);
  22.   Win.SetSize(80, 25);
  23.   Win.SetLocn(30, 7);
  24.  
  25.   // Save a 23 x 7 portion of the screen starting at this region 
  26.   // into a save buffer, allocated off the heap 
  27.  
  28.   TxBuff SaveBuff(0);
  29.   SaveBuff.SetSize(23, 7);
  30.   SaveBuff.Xfr(0, 0, 23, 7, &Win, 0, 0);
  31.  
  32.   // Draw a white window with a shadow. Note that the shadow only 
  33.   // shows up in color mode. Coordinates are relative to Win.     
  34.  
  35.   Win.Fill(0, 0, 21, 6, ' ', 0x70);
  36.   Win.FillB(21, 1, 2, 6, 0x08, 1); // vertical shadow 
  37.   Win.FillB(1, 6, 22, 1, 0x08, 1); // horizontal shadow 
  38.  
  39.   // Put some lines of text on the window. Note how we must skip 
  40.   // over the length byte, and  pass the length of the string. 
  41.  
  42.   Win.HzWrtB(1, 1, "I am a window. Use");
  43.   Win.HzWrtB(1, 2, "shift arrow keys to");
  44.   Win.HzWrtB(1, 3, "move me. Use ENTER");
  45.   Win.HzWrtB(1, 4, "key to quit ...   ");
  46.  
  47.   // Move the window in an event loop. Look for shift arrow
  48.   // keys, and move the window by swapping to and from
  49.   // the save buffer. Quit when Esc key is pressed and put
  50.   // window back where it came from. 
  51.  
  52.   X = 30; Y = 7;
  53.  
  54.   do {
  55.     K = bioskey(0);  // Wait for keypress
  56.     if (IsShiftArrow(K))  {
  57.        Scrn.Swap(X, Y, 23, 7, &SaveBuff, 0, 0);  // Hide
  58.        switch (K) {
  59.          case ShiftLeft:  if (X > 0)  X--;      break;
  60.          case ShiftRight: if (X < (80-23)) X++; break;
  61.          case ShiftUpKey: if (Y > 0)  Y--;      break;
  62.          case ShiftDnKey: if (Y < (25-7)) Y++;  break;
  63.          default: ;
  64.        }
  65.        Scrn.Swap(X, Y, 23, 7, &SaveBuff, 0, 0);  // Show
  66.        Win.SetLocn(X, Y); // Make sure to set new location too! 
  67.     }
  68.   } while (K != CrKey);
  69.  
  70.   /* Move window back to center */
  71.  
  72.   Scrn.Swap(X, Y, 23, 7, &SaveBuff, 0, 0);
  73.   Scrn.Swap(30, 7, 23, 7, &SaveBuff, 0, 0);
  74.   Win.SetLocn(30,7); // Make sure to set window coordinates 
  75.  
  76.   // Put new messages up. go through loop and move
  77.   // a little single character scanner until keypress
  78.  
  79.   Win.Fill(0, 0, 21, 6, ' ', 0x70);
  80.   Win.HzWrtB(2, 1, "Now, below is a ");
  81.   Win.HzWrtB(2, 2, "scanner. Press  ");
  82.   Win.HzWrtB(2, 3, "Enter to stop it");
  83.  
  84.   X = 0;
  85.   do {
  86.    Win.Fill(X,4,1,1,' ',0x70);  // Erase scanner
  87.    if (X < 19) X++; else X = 1;
  88.    Win.Fill(X,4,1,1,176,0x70);  // Draw scanner
  89.    delay(10);
  90.    K = KeyEvent();  // Look for, but don't wait for keypress
  91.   } while (K == 0);
  92.  
  93.   // Now put up some menu entries. Use up and down arrow to
  94.   // select menu entry. Cr Key selects choice, Esc Key quits. 
  95.  
  96.   char *MenuChoices[4] = {
  97.     "Do Something",
  98.     "Be Lazy     ",
  99.     "Just Say No ",
  100.     "Go to Miami "
  101.   };
  102.  
  103.   Win.Fill(0, 0, 21, 6, ' ', 0x70);
  104.   Win.HzWrtB(1, 1, MenuChoices[0]);
  105.   Win.HzWrtB(1, 2, MenuChoices[1]);
  106.   Win.HzWrtB(1, 3, MenuChoices[2]);
  107.   Win.HzWrtB(1, 4, MenuChoices[3]);
  108.  
  109.   Win.HzWrt(0, 8,  "Use arrow keys to move", 0x7f);
  110.   Win.HzWrt(0, 9,  "highlight. Use ENTER  ", 0x7f);
  111.   Win.HzWrt(0, 10, "to select, ESC to     ", 0x7f);
  112.   Win.HzWrt(0, 11, "abort ...             ", 0x7f);
  113.  
  114.   X = 1; Y = 1;
  115.   Win.HzFillB(X, Y, 0x07, 1, 19);     // Put up first highlight 
  116.  
  117.   do {
  118.     K = bioskey(0);                   // Wait for key
  119.     Win.HzFillB(X, Y, 0x70, 1, 19);   // Erase old highlight
  120.     switch (K) {
  121.       case UpKey:   if (Y > 1)  Y--; else Y = 4; break;
  122.       case DownKey: if (Y < 4) Y++; else Y = 1;  break;
  123.       default: ;
  124.     }
  125.     Win.HzFillB(X, Y, 0x07, 1, 19);   // Put up new highlight
  126.   } while ((K != CrKey) && (K != EscKey));
  127.  
  128.   Win.Fill(0, 8, 22, 4, 176, 0x0f);
  129.  
  130.   // Process the choice
  131.  
  132.   if (K == CrKey)  {
  133.      char Saywhat[80];
  134.      strcpy(Saywhat, "Sorry, we won't let you ");
  135.      strcat(Saywhat, MenuChoices[Y-1]);
  136.      Win.HzWrt(0, 8, Saywhat, 0x7f);
  137.   }
  138.   else {
  139.      Win.HzWrt(0, 8, "Can't make up your mind, huh?", 0x7f);
  140.   }
  141.  
  142.  
  143.   // Scroll up a line. Put in another menu entry
  144.  
  145.   Win.HzWrt(0, 9, "But press RETURN and watch the menu scroll!", 0x7f);
  146.   bioskey(0);
  147.  
  148.   Win.Scroll(1, 1, 19, 4, UpScroll, 1);
  149.   Win.HzWrtB(1, 4, "*** The End ***");
  150.  
  151. }
  152.